<template>
	<view>
		<input type="text" v-model="name"/>
		<input type="text" v-model="password"/>
		<button @click="Login">登录</button>
		<p @click="Zc">去注册</p>
	</view>
</template>

<script setup>
	import {ref} from 'vue'
	let name = ref("")
	let password = ref('')
	let list = ref([])
const Login=()=>{
    uni.request({
        url: 'http://47.94.6.186:3001/api/user/login',
        method: 'POST', 
        data: {
            loginname: name.value,
			password:password.value,
        },
        success: (res) => {
            console.log(res.data.data);
			list.value = res.data.data
			let loginToken = res.data.data.token
			let loginUserid = res.data.data.userid
			uni.setStorageSync("token", loginToken);
			uni.setStorageSync("userid", loginUserid);
			setTimeout(() => {
			      uni.switchTab({
			          url: "/pages/cart/cart"
			      })      
			     }, 1000);
        },
        fail: () => {

        },
        complete: () => {
        }
    });
}
function Zc(){
	setTimeout(() => {
	      uni.navigateTo({
	          url: "/pages/reg/reg"
	      })      
	     }, 1000);
}
</script>

<style>

</style>
